package cn.edu.scnu.semart.goods.mapper;

import cn.edu.scnu.semart.model.goods.Like;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 用户点赞Mapper接口
 */
@Mapper
public interface LikeMapper extends BaseMapper<Like> {

    /**
     * 查询所有（包括逻辑删除）的商品点赞记录
     */
    @Select("SELECT * FROM user_like WHERE user_id = #{userId} AND goods_id = #{goodsId} AND like_type = 1 LIMIT 1")
    Like selectAnyGoodsLike(@Param("userId") Integer userId, @Param("goodsId") Integer goodsId);

    /**
     * 查询所有（包括逻辑删除）的评论点赞记录
     */
    @Select("SELECT * FROM user_like WHERE user_id = #{userId} AND target_id = #{commentId} AND like_type = 2 LIMIT 1")
    Like selectAnyCommentLike(@Param("userId") Integer userId, @Param("commentId") Integer commentId);

    /**
     * 恢复商品点赞（将deleted=1的记录恢复为0）
     */
    @Update("UPDATE user_like SET deleted = 0 WHERE id = #{id}")
    int restoreGoodsLike(@Param("id") Integer id);

    /**
     * 恢复评论点赞（将deleted=1的记录恢复为0）
     */
    @Update("UPDATE user_like SET deleted = 0 WHERE id = #{id}")
    int restoreCommentLike(@Param("id") Integer id);
} 